package web.controller;

import java.util.Map;

import web.common.BaseGenerator;
import web.common.CodeEngineConfig;
import web.config.ManagerBeanModifier;
import web.config.ServletBeanModifier;
import web.config.TilesBeanModifier;
import web.config.SecurityBeanModifier;

/**
 * Created by IntelliJ IDEA.
 * User: duanbin
 * Date: 2007-8-21
 * Time: 17:46:37
 * To change this template use File | Settings | File Templates.
 */
public class ControllerGenerator extends BaseGenerator {
    public static void main(String[] args) {
        (new ControllerGenerator()).generate();
    }

    public String getFileName(String name) {
        return name + CodeEngineConfig.CONTROLLER_FILE_SUFFIX; 
    }
    public void prepareData(Map root, String name) {
        root.put("name",name);
        root.put("managers",CodeEngineConfig.getControllerManagers(name));
        root.put("services",CodeEngineConfig.getControllerServices(name));
        root.put("extends",CodeEngineConfig.getControllerExtends(name));
    }
    protected void afterGenerate(String name){
         if(CodeEngineConfig.generateSpringBeanDef(name)){
             ManagerBeanModifier beanDefGenerator = new ManagerBeanModifier();
             beanDefGenerator.modify(name);

             ServletBeanModifier servletBeanModifier = new ServletBeanModifier();
             servletBeanModifier.modify(name);

             if(CodeEngineConfig.LAYOUT_COMPONENT_TILES.equalsIgnoreCase(
                     CodeEngineConfig.getSpringLayoutComponent())){
                 TilesBeanModifier tilesBeanModifier = new TilesBeanModifier();
                 tilesBeanModifier.modify(name);
             } //else using sitemesh  todo

             if(name.endsWith("Mgr")){
                 SecurityBeanModifier securityBeanModifier = new SecurityBeanModifier();
                 securityBeanModifier.modify(name);
             }//else using common rights

            /* todo 
              sitemeth, acegi, map and control
              pagination, base manager have a common method, maybe like this: pageInfo queryForPagination("managerMethName", params);
              message properties
              controller and mgrcontroller
              increasing develop automaticlly
              */

         }
    }

 
}
